// pages/home/home.js
import {
  channels,
  articles
} from '../../api/home'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    FormList: [],
    isboolean: true,
    active:0,
    channel_id:0,
    with_top:1,
    timestamp:null,
    HomeList:[],
  },
  async  ClickTabsId(e){
    this.setData({
      HomeList:[]
    })
    this.getList()
    console.log(e);
        this.setData({
          channel_id:this.data.FormList[e.detail.index].id,
        })
        
   },
//  async homeArticles(){
//     const res = articles()
//    },
DetailsPage (e){
  const id=e.currentTarget.dataset.id
  wx.navigateTo({
    url: '/pages/DetailsPage/DetailsPage?id='+id
  })
  console.log(e);
},
  // async homeList() {
  //   const res = await channels()
  //   this.setData({
  //     FormList: res.data.channels
  //   })
  //   // this.selectComponent('#tabs').resize();
  // },
 async getList(){
  const res = await articles({
    channel_id:this.data.channel_id ,
     timestamp:+ (new Date),
     with_top:1})
     this.setData({
      HomeList:[...this.data.HomeList,...res.data.results]
    })

  },
  JumpSearch(){
    wx.redirectTo({
      url: '/pages/search/search',
    })
  },
  // 下拉刷新
    onpulling() {
      setTimeout(()=>{
        this.setData({
          isboolean: false
        })
      },1000)
    wx.stopPullDownRefresh()
    // this.homeList()
    this.ClickTabsId()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    
    const res1 = await channels()
    this.setData({
      FormList: res1.data.channels
    })
    this.getList()
    // console.log(this.data.FormList);
    
    // this.ClickTabsId()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  }, 

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // this.ClickTabsId()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})